package org.jpro.modules.system.utils;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.jpro.modules.system.entity.User;
import org.jpro.modules.system.realm.AuthorizingRealm;

public class UserUtil {
    /**
     * 获取当前用户对象shiro
     * @return shirouser
     */
    public static AuthorizingRealm.ShiroUser getCurrentShiroUser() {
        AuthorizingRealm.ShiroUser user = (AuthorizingRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
        return user;
    }

    /**
     * 获取当前用户session
     * @return session
     */
    public static Session getSession() {
        Session session = SecurityUtils.getSubject().getSession();
        return session;
    }

    /**
     * 获取当前用户httpsession
     * @return httpsession
     */
    public static Session getHttpSession() {
        Session session = SecurityUtils.getSubject().getSession();
        return session;
    }

    /**
     * 获取当前用户对象
     * @return user
     */
    public static User getCurrentUser() {
        Session session = UserUtil.getSession();
        if (null != session) {
            return (User) session.getAttribute("user");
        } else {
            return null;
        }

    }
}
